/* eslint-disable */
export default  class Util {

  static generateGUID() {
    var d = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
      function(c) {
        var r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c == 'x' ? r: (r & 0x3 | 0x8)).toString(16);
      });
    return uuid;

  }

  static equalZero(a) {
    return  Math.abs(a) < 0.0000001;
  }

  static toFixed(num,d){
    num *=Math.pow(10,d);
    num = Math.round(num);
    return num/(Math.pow(10,d));
  }

  //原生元素宽度度
  static width(el){
    let _width = el.clientWidth;
    let style = el.currentStyle || window.getComputedStyle(el);
    return _width - (parseInt(style.paddingLeft) + parseInt(style.paddingRight));
  }

  //原生元素高度
  static height(el){
    let _height = el.clientHeight;
    let style = el.currentStyle || window.getComputedStyle(el);
    return _height - (parseInt(style.paddingTop) + parseInt(style.paddingBottom));
  }

//javascrit原生实现jquery的append()函数
  static append(parent, text) {
    if (typeof text === 'string') {
      var temp = document.createElement('div');
      temp.innerHTML = text;
      // 防止元素太多 进行提速
      var frag = document.createDocumentFragment();
      while (temp.firstChild) {
        frag.appendChild(temp.firstChild);
      }
      parent.appendChild(frag);
    }
    else {
      parent.appendChild(text);
    }
  }


  static cesiumRgb2Hex(rgb) {

    return("#" + ((1 << 24) + (rgb.red*255 << 16) + (rgb.green*255 << 8) + rgb.blue*255))
        .toString(16)
        .slice(1);
  }

  static exportSVG(svg){

    // https://developer.mozilla.org/en/DOM/window.btoa;
    return "data:image/svg+xml;base64," + btoa(svg);
  }


  static getDataURI (svg,color) {
    //var hexColor = this.cesiumRgb2Hex(color); // get the hex color to fill
    var reg = new RegExp( '#2EC2CE' , "g" )
    var svg1 = svg.replace( reg , color );
    return this.exportSVG(svg1);
    //return "data:image/svg+xml;base64," + btoa(svg);
  }


}


